#include "pch.h"

#include "core/referencecount.h"



namespace Core
{
	RE_ImplementRootClass('REFC', Core::ReferenceCount);

	///
	ReferenceCount::ReferenceCount():
	m_refCount(0)
	{

	}

	///
	ReferenceCount::~ReferenceCount()
	{

	}


	///
	void ReferenceCount::AddRef()
	{
		Threading::Interlocked::Increment(this->m_refCount);
	}


	///
	void ReferenceCount::Release()
	{
		if(Threading::Interlocked::Decrement(this->m_refCount) == 0)
			r_delete(this);
	}


	///
	int ReferenceCount::GetRefCount() const 
	{
		return this->m_refCount;
	}


	///
	bool ReferenceCount::IsInstOf(const Rtti & other) const 
	{
		return this->GetRtti() == &other;
	}


	///
	bool ReferenceCount::IsInstOf(const Helper::String & other) const 
	{
		return this->GetRtti()->GetName() == other;
	}


	///
	bool ReferenceCount::IsInstOf(const Helper::FCC & other) const 
	{
		return this->GetRtti()->GetFCC() == other;
	}


	///
	bool ReferenceCount::IsA(const Rtti & other) const
	{
		return this->GetRtti()->DerivesFrom(other);
	}


	///
	bool ReferenceCount::IsA(const Helper::String & name) const 
	{
		return this->GetRtti()->DerivesFrom(name);
	}


	///
	bool ReferenceCount::IsA(const Helper::FCC &fcc) const
	{
		return this->GetRtti()->DerivesFrom(fcc);
	}


	///
	const Helper::String & ReferenceCount::GetNameOfClass() const 
	{
		return this->GetRtti()->GetName();
	}


	///
	const Helper::FCC ReferenceCount::GetFCCOfClass() const 
	{
		return this->GetRtti()->GetFCC();
	}

}